package com.be.beadmin.basicData.controller;

import com.alibaba.fastjson.JSONArray;

import com.be.beadmin.basicData.dto.input.MenuDto;
import com.be.beadmin.basicData.dto.input.MenuParentFilter;
import com.be.beadmin.basicData.service.MenuService;
import com.be.beadmin.common.utils.ResultModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
@Api(tags = "系统权限模块")
@RestController
public class MenuController {

    @Autowired
    MenuService menuService;

    /**
     * 根据Menu的父ID分页查询
     * @param menuParentFilter
     * @return
     */
    @ApiOperation("获取所有菜单")
    @PostMapping("/system/getMenuByPage")
    public ResultModel getMenuByPage(@RequestBody MenuParentFilter menuParentFilter){
        return ResultModel.success(menuService.getMenuByPage(menuParentFilter));
    }

    /**
     * 加载MENU的菜单树
     * @return
     */
    @ApiOperation("菜单树")
    @PostMapping("/system/getMenuTree")
    public ResultModel getMenuTree(){
        JSONArray array = menuService.getMenuTree();
        return ResultModel.success(array);
    }


    @ApiOperation("添加菜单")
    @PostMapping("/system/addMenu")
    public ResultModel addMenu(@RequestBody MenuDto menuDto){
        menuService.addMenu(menuDto);
        return ResultModel.success(ResultModel.ADD);
    }

    @ApiOperation("更新菜单")
    @PostMapping("/system/updateMenu")
    public ResultModel updateMenu(@RequestBody MenuDto menuDto){
       menuService.updateMenu(menuDto);
        return ResultModel.success(ResultModel.UPDATE);
    }

    @ApiOperation("删除菜单")
    @PostMapping("/system/delMenu")
    public ResultModel delMenu(@RequestBody MenuDto menuDto){
       menuService.delMenu(menuDto);
       return ResultModel.success(ResultModel.DELETE);
    }

}
